<template>
	<view class="storeBox">
		<myHeader :checkIndex='1'></myHeader>
		<view class="searchBox">
			<view class="inputBox">
				<u-input type="text" placeholder="请输入地址、序号、姓名、手机号后四位进行搜索" icon="search" v-model="nameTakingMeal"
					confirm-type="search" @confirm="getStoreDataList"></u-input>
				<image src="https://www.yongshantuan.cn/images/yongshan/search.png" mode=""></image>
				<view class="searchButton" @click="getStoreDataList">搜索</view>
			</view>
			<view class="">{{dataInfo.merchantCount}} 家门店，总订单量 {{dataInfo.orderCount}} 单</view>
		</view>
		<view class="dataContent">
			<view class="dataList" v-for="(item,index) in dataList" :key="index">
				<view class="name">
					<view class="">
						<image :src="item.logo|getImg" mode="">
						</image>
						{{item.storeName}}
					</view>
					<view class="">
						序号：<text>{{item.pickingSerialNo}}</text>
					</view>
				</view>
				<view class="list">
					<view class="">
						姓名：<text>{{item.nameTakingMeal}}</text>
					</view>
					<view class="">
						手机号：<text @click="toCall(item.phoneTakingMeals)">{{item.phoneTakingMeals}}</text>
					</view>
				</view>
				<view class="list">
					<view class="">
						地址：<text>{{item.supplyAddress}}</text>
					</view>
				</view>
				<view class="list foods">
					<view class="">
						<view class="">菜品：</view>
						<view class="">
							<text v-for="(foodItem,foodIndex) in item.hcOrderDetailedList" :key="foodIndex">
								<text>{{foodItem.tradeName}}</text>
								<text
									:class="{'error':foodItem.commodityQuantity>1}">x{{foodItem.commodityQuantity}}</text>
								<text v-if="foodIndex!=item.hcOrderDetailedList.length-1">,</text>
							</text>
						</view>
					</view>
				</view>
				<view class="list">
					<view class="">
						下单累计次数：<text>{{item.orderCount}}</text>
					</view>
				</view>
				<view class="list">
					<view class="">
						消费金额：<text>{{item.totalPrice}}</text>
					</view>
				</view>
				<view class="list">
					<view class="">
						付款时间：<text>{{item.payTimeStr}}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getStoreDataList,
		getStoreDataInfo
	} from '@/utils/req/api.js'
	import MyHeader from '../../components/header/header.vue'
	export default {
		components: {
			MyHeader
		},
		data() {
			return {
				dataList: [],
				dataInfo: {},
				nameTakingMeal: '',

				pageSize: 10,
				pageNo: 1,
				moreFlag: false
			}
		},
		onShow() {
			this.getStoreDataList();
			this.getStoreDataInfo();
		},
		methods: {
			async getStoreDataList(type) {
				let res = await getStoreDataList({
					pageSize: this.pageNo * this.pageSize,
					pageNo: 1,
					nameTakingMeal: this.nameTakingMeal
				});
				this.dataList = [];
				this.dataList = res.data.result.records;
			},
			async getStoreDataInfo() {
				let res = await getStoreDataInfo();
				this.dataInfo = res.data.result;
			},
			toCall(phone) {
				uni.makePhoneCall({
					phoneNumber: phone
				})
			}
		},
		onReachBottom() {
			if (!this.moreFlag) {
				if (this.dataList.length != 0 && this.dataList.length % this.pageSize == 0) {
					this.pageNo = this.pageNo + 1;
					this.moreFlag = true
					this.getStoreDataList('push');
					setTimeout(() => {
						this.moreFlag = false;
					}, 1000)
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.storeBox {
		background-color: #F5F5F5;
		padding-bottom: 40rpx;
		min-height: 100vh;
	}

	.searchBox {
		padding: 20rpx 40rpx;
		background-color: #fff;
		border: 1px solid #eee;

		.inputBigBox {
			@include flex(space-between, center);
		}

		.searchButton {
			background-color: #FA690A;
			color: #fff;
			border-radius: 60rpx;
			font-size: 28rpx;
			line-height: 50rpx;
			padding: 0 20rpx;
			position: absolute;
			right: 10rpx;
			top: 10rpx;
		}

		.inputBox {
			width: 100%;
			position: relative;

			image {
				width: 40rpx;
				height: 40rpx;
				position: absolute;
				left: 10rpx;
				top: calc((100% - 40rpx) / 2);
			}

			.u-input {
				font-size: 28rpx;
				line-height: 2;
				background-color: #f5f5f5;
				border-radius: 100rpx;
				padding: 0 60rpx !important;

				.u-input_input {
					color: red;
				}
			}
		}

		>view:nth-child(2) {
			font-size: 28rpx;
			color: #FA690A;
			line-height: 2;
			text-align: center;
			margin-top: 20rpx;
		}
	}

	.dataList {
		padding: 40rpx;
		margin: 20rpx 0;
		background-color: #fff;

		>.name {
			@include flex(space-between, center);
			margin-bottom: 20rpx;

			>view {
				@include flex();
				font-size: 32rpx;
				line-height: 2;

				image {
					width: 40rpx;
					height: 40rpx;
					margin-right: 20rpx;
				}

				&:nth-child(2) {
					border-radius: 100rpx;
					padding: 0 20rpx;
					// color: rgba(0, 0, 0, 0.55);
					color: #000;

					text {
						color: #000
					}
				}
			}
		}

		>.list {
			@include flex();
			font-size: 32rpx;
			line-height: 2;
			// margin: 10rpx 0;
			flex-wrap: wrap;

			text {
				// margin-left: 10rpx;
			}

			.error {
				color: #E06262;
			}

			.ing {
				color: #6ABCEB;
			}

			.success {
				color: #7CCF85;
			}


			>view {
				// width: 50%;
				margin-right: 20rpx;
				line-height: 2;
				flex-wrap: wrap;

				// color: rgba(0, 0, 0, 0.55);
				color: #000;

				text {
					color: #000;
				}
			}
		}

		>.foods {
			line-height: 32rpx;

			>view {
				@include flex(flex-start, flex-start);
				line-height: 2;

				>view {
					&:nth-child(2) {
						flex: 1;
					}

					.error {
						color: red;
						font-size: 32rpx;
						font-weight: bold;
					}
				}
			}
		}
	}
</style>